package com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.qingyiapp.R;
import com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Entify.Findfriendentity;
import com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Interface.IOnClickListener;

import java.util.ArrayList;

/**
 * @author ：created by 申德丰
 * Create Date ：2019/9/20 14:44
 * Package_Name : QingYiApp
 */
public class FindfriendADpter extends RecyclerView.Adapter<FindfriendADpter.MYviewHolder> {


    ArrayList<Findfriendentity> findfriendentities;
    Context context;
    IOnClickListener iOnClickListener;

    public void setiOnClickListener(IOnClickListener iOnClickListener) {
        this.iOnClickListener = iOnClickListener;
    }

    public FindfriendADpter(ArrayList<Findfriendentity> findfriendentities, Context context) {
        this.findfriendentities = findfriendentities;
        this.context = context;
    }

    @NonNull
    @Override
    public MYviewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View inflate = LayoutInflater.from(context).inflate(R.layout.fragment_find_friend_xre_item, viewGroup, false);
        return new MYviewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull MYviewHolder mYviewHolder, final int i) {

        Glide.with(context).load(findfriendentities.get(i).getUsercover()).apply(RequestOptions.circleCropTransform()).into(mYviewHolder.imageView);
        mYviewHolder.name.setText(findfriendentities.get(i).getName());
        mYviewHolder.xq.setText(findfriendentities.get(i).getDescription());

        mYviewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iOnClickListener.onxreviewitemonclick(i);
            }
        });

    }

    @Override
    public int getItemCount() {
        return findfriendentities.size();
    }

    class MYviewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView name, xq;
        public MYviewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.find_friend_head);
            name=itemView.findViewById(R.id.find_feiend_name);
            xq=itemView.findViewById(R.id.find_friend_xq);
        }
    }
}
